/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.dbmapping.persistence;

import com.elcom.emocbc.dbmapping.tables.daos.MtpkgScheduleDao;
import org.jooq.Configuration;
import org.jooq.ConnectionProvider;
import org.jooq.SQLDialect;
import org.jooq.conf.Settings;
import org.jooq.conf.StatementType;
import org.jooq.impl.DefaultConfiguration;

/**
 *
 * @author GiangLT
 */
public class MtpkgSchedulePersistance extends MtpkgScheduleDao {

    public MtpkgSchedulePersistance() {
        ConnectionProvider connectionProvider = new DbConnectionProvider();
        Settings settings = new Settings();
        settings.setStatementType(StatementType.STATIC_STATEMENT);
        Configuration configuration = new DefaultConfiguration()
                .set(connectionProvider)
                .set(SQLDialect.ORACLE)
                .set(settings);
        this.setConfiguration(configuration);
    }

//    public List<MtpkgSchedule> findAllWithPkgName() throws SQLException {
//        Connection con = this.configuration().connectionProvider().acquire();
//        QueryRunner qr = new QueryRunner();
//        String sql = "SELECT s.* , p.pkg_name "
//                + " FROM mtpkg_schedule s "
//                + " INNER JOIN mtpkg_package p ON p.pkg_id = s.pkg_id "
//                + " ORDER BY p.pkg_name";
//        try {
//            return qr.query(con, sql, new MtpkgScheduleListResultSetHandler());
//        } finally {
//            this.configuration().connectionProvider().release(con);
//        }
//    }
//
//    public List<MtpkgSchedule> fetchByPkgName(String pkgName) throws SQLException {
//        Connection con = this.configuration().connectionProvider().acquire();
//        QueryRunner qr = new QueryRunner();
//        String sql = "SELECT s.* "
//                + " FROM mtpkg_schedule s "
//                + " INNER JOIN mtpkg_package p ON p.pkg_id = s.pkg_id "
//                + " WHERE p.pkg_name = ? "
//                + " ORDER BY p.pkg_name";
//        try {
//            return qr.query(con, sql, new MtpkgScheduleListResultSetHandler(), pkgName);
//        } finally {
//            this.configuration().connectionProvider().release(con);
//        }
//    }
//
//    private class MtpkgScheduleListResultSetHandler implements ResultSetHandler<List<MtpkgSchedule>> {
//
//        @Override
//        public List<MtpkgSchedule> handle(ResultSet rs) throws SQLException {
//            List<MtpkgSchedule> result = new ArrayList<MtpkgSchedule>();
//            while (rs.next()) {
//                MtpkgSchedule schedule = new MtpkgSchedule();
//                int i = 1;
//                schedule.setPkgdId(rs.getString(i++));
//                schedule.setSendTime(rs.getTimestamp(i++));
//                schedule.setScheduleId(rs.getBigDecimal(i++));
//                schedule.setIsInterval(rs.getByte(i++));
//                schedule.setStatus(rs.getByte(i++));
//                schedule.setTimeType(rs.getBigDecimal(i++));
//                schedule.setTimeSelect(rs.getString(i++));
////                schedule.setPkgName(rs.getString(i++));
//                result.add(schedule);
//            }
//            return result;
//        }
//    }
}
